/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package util;

import com.google.gson.Gson;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.StringReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.text.BadLocationException;
import javax.swing.text.html.HTML;
import javax.swing.text.html.HTML.Tag;
import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.HTMLEditorKit;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
/**
 *
 * @author Desarrollo
 */
public class Excel {

    public Excel() {

    }

    public static String HTML2Excel(String u, String f) {
        System.out.println("url: " + u);
        System.out.println("file: " + f);
        
        BufferedReader in = null;
        try {
            String html = "", line;
            URL url = new URL(u);
            in = new BufferedReader(new InputStreamReader(url.openStream()));
            while ((line = in.readLine()) != null) html += line;

            int p = 0, nt = html.length();

            while (p < nt) {
                int pi = html.indexOf("<tr>", p) + 4;
                int pf = html.indexOf("</tr>", pi);
                String tr = html.substring(pi, pf);

                System.out.println("tr: " + tr);
                p = pf + 5;
            }

        } catch (IOException ex) {
            Logger.getLogger(Excel.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            try {
                in.close();
            } catch (IOException ex) {
                Logger.getLogger(Excel.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

        return "OK";
    }
}
